package cn.iocoder.yudao.module.mon.controller.admin.mon;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.mon.controller.admin.mon.vo.AddDeviceReqVo;
import cn.iocoder.yudao.module.mon.controller.admin.mon.vo.DeleteDeviceReqVo;
import cn.iocoder.yudao.module.mon.controller.admin.mon.vo.UpdateDeviceReqVo;
import cn.iocoder.yudao.module.mon.service.MonService;
import io.swagger.v3.oas.annotations.Operation;  
    import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 平台设备")
@RestController
@RequestMapping("/mon/ys7")
@Validated
public class MonYs7Controller {

    @Resource
    private MonService monService;

    @PostMapping("/addDeviceInfo")
    @Operation(summary ="添加设备")
    @PreAuthorize("@ss.hasPermission('mon:ys7:addDevice')")
    public CommonResult<Long> addDeviceInfo(@Valid @RequestBody AddDeviceReqVo context) {
        return success( monService.addDeviceInfo(context));
    }


    @PostMapping("/updateDeviceInfo")
    @Operation(summary ="修改设备")
    @PreAuthorize("@ss.hasPermission('mon:ys7:updateDevice')")
    public CommonResult<Boolean> updateDeviceInfo(@Valid @RequestBody UpdateDeviceReqVo context) {
        monService.updateDeviceInfo(context);
        return success(true);
    }

    @PostMapping("/deleteDeviceInfo")
    @Operation(summary ="删除设备")
    @PreAuthorize("@ss.hasPermission('mon:ys7:deleteDevice')")
    public CommonResult<Boolean> deleteDeviceInfo(@Valid @RequestBody DeleteDeviceReqVo context) {
        monService.deleteDeviceInfo(context);
        return success(true);
    }


    @GetMapping("/getDeviceSecret")
    @Operation(summary ="获取设备token")
    @PreAuthorize("@ss.hasPermission('mon:ys7:addDevice')")
    public CommonResult<String> getDeviceSecret( ) {
        return success(monService.getTokenCache());
    }
}
